import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
public class Methods
{
    public static double round(double number, int exponent) 
    { 
    	if(Double.isNaN(number))
			return Double.NaN; 
    	double result;
    	BigDecimal res;
    	res = new BigDecimal(number).setScale(exponent, BigDecimal.ROUND_UP);
    	result = res.doubleValue();
    	return result; 
    }
    public static int calculateAge(Date bornDate) {
		Calendar cal = Calendar.getInstance();
		int currYear = cal.get(Calendar.YEAR);
    	int currMonth = cal.get(Calendar.MONTH);
    	int currDay = cal.get(Calendar.DAY_OF_MONTH);
    	cal.setTime(bornDate);
    	int years = currYear - cal.get(Calendar.YEAR);
    	int bornMonth = cal.get(Calendar.MONTH);
    	if (bornMonth == currMonth) 
    	{
    		return cal.get(Calendar.DAY_OF_MONTH) <= currDay ? years : years - 1;
    	} else 
    	{
    		return bornMonth < currMonth ? years - 1 : years;
    	}
    }
    public static int calculateAge(Date date,Date bornDate) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		int currYear = cal.get(Calendar.YEAR);
    	int currMonth = cal.get(Calendar.MONTH);
    	int currDay = cal.get(Calendar.DAY_OF_MONTH);
    	cal.setTime(bornDate);
    	int years = currYear - cal.get(Calendar.YEAR);
    	int bornMonth = cal.get(Calendar.MONTH);
    	if (bornMonth == currMonth) 
    	{
    		return cal.get(Calendar.DAY_OF_MONTH) <= currDay ? years : years - 1;
    	} else 
    	{
    		return bornMonth < currMonth ? years - 1 : years;
    	}
    }
}
